package com.lxc.controller;

import com.lxc.entity.Chapters;
import com.lxc.entity.Result;
import com.lxc.service.ChapterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/chapter")
public class ChapteriesController {
    @Autowired
    private ChapterService chapterService;

    @GetMapping("/{chapterid}")
    public Result<Chapters> getChapter(@PathVariable Integer chapterid) {
//        log.info("查询章节内容：{}", chapterService.getByChapterId(chapterid));
        return Result.success(chapterService.getByChapterId(chapterid));

    }

    @PostMapping
    public Result addChapter(@RequestBody Chapters chapter) {
        return Result.success(chapterService.saveChapter(chapter));
    }

    @DeleteMapping("/{chapterid}")
    public Result deleteChapter(@PathVariable Integer chapterid) {
        return Result.success(chapterService.deleteByChapterId(chapterid));
    }
}